package academic.ui.client.presenter;


import academic.ui.client.place.Tokens;

import com.allen_sauer.gwt.log.client.Log;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.EventBus;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.NameToken;
import com.gwtplatform.mvp.client.annotations.ProxyStandard;
import com.gwtplatform.mvp.client.proxy.PlaceRequest;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;
import com.gwtplatform.mvp.client.proxy.RevealContentEvent;

public class ProductPlacePresenter extends 
Presenter<ProductPlacePresenter.MyView,ProductPlacePresenter.MyProxy>{

	private ProductPresenter productPresenter;

	@Inject
	public ProductPlacePresenter(EventBus eventBus, MyView view, MyProxy proxy,ProductPresenter productPresenter) {
		super(eventBus, view, proxy);
		this.productPresenter=productPresenter;
	}
	
	public final String TOKEN_TYPE = "id";
	
	public String productID; 

	@ProxyStandard
	@NameToken(Tokens.productFull)
	public interface MyProxy extends ProxyPlace<ProductPlacePresenter>  {}

	public interface MyView extends View {
		
	}

	@Override
	protected void revealInParent() {
		RevealContentEvent.fire(this, ProductPresenter.SLOT,this);
		Log.debug("ProductPlacePresenter revealInParent");
	}
	
	@Override
	public void onReveal() {
		super.onReveal();
		Log.debug("ProductPlacePresenter onReveal");
	}
	
	@Override
	public void prepareFromRequest(PlaceRequest request) {
		super.prepareFromRequest(request);
		productPresenter.productID=request.getParameter(TOKEN_TYPE,null);
		if(request.getParameter("expired", null)!=null)
			productPresenter.getView().setExpired(true);
		else
			productPresenter.getView().setExpired(false);
	}
	
	@Override
	public void onBind() {
		super.onBind();
		Log.debug("ProductPlacePresenter onBind");
	}
	
	@Override
	public void onReset() {
		super.onReset();
		Log.debug("ProductPlacePresenter onReset");
	}
	
	
}
